package com.dollar.ArtConcurrentBook.chap5;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class MutexTest {
    public static void main(String[] args) throws InterruptedException {
        Adder adder = new Adder();
        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 10000; i++) {
                    adder.addOne();
                }
            }
        }, "threadA");

        Thread thread2 = new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 10000; i++) {
                    adder.addOne();
                }
            }
        }, "threadB");
        thread.start();
        thread2.start();
        thread.join();
        thread2.join();
        System.out.println("-----" + adder.getCount());
    }
}
